﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.SpecialUtils.View;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RabbitDownload.MangerTool
{
    public partial class MangerToolingControl : UserControl
    {
        public MangerToolingControl()
        {
            InitializeComponent();
            InitView();
        }

        private void InitView()
        {
            comboBox1.SelectedIndex = 0;
            for (double i = 0.1; i <= 2.1; i += 0.1)
            {
                comboBox2.Items.Add(i.ToString("F1"));
            }
            comboBox2.SelectedIndex = 4;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            Helper.ViewHelper.TextBoxHelper.PrintCount(e);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.DeleteForSize(FloderPath, TextHelper.StringToInt(textBox1.Text));
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.ImgCompress(FloderPath, comboBox1.Text);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.DeleteImgForProportion(FloderPath, Convert.ToSingle(comboBox2.Text));
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.ReSize(FloderPath, TextHelper.StringToInt(textBox2.Text));
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.DeleteForSizeOrInfo(FloderPath, TextHelper.StringToInt(textBox5.Text), TextHelper.StringToInt(textBox3.Text), TextHelper.StringToInt(textBox4.Text));
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            String FloderPath = FloderHelper.SelectFloder();
            if (MessageHelper.AlertNull(FloderPath))
            {
                FileControlTool.SplitFloder(FloderPath, TextHelper.StringToInt(textBox6.Text), checkBox1.Checked);
                MessageHelper.Alert("切割完毕，放置该文件夹的temp文件夹中。");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            FloderHelper.FloderExits(new FileControlTool().PropagandaPath, true);
            FloderHelper.OpenFloder(new FileControlTool().PropagandaPath);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            string FilePath = FileHelper.SelectFile();
            List<string> AllList = FileHelper.ReadAllLine(FilePath);
            AllList = ListHelper.ListRepeat(AllList);

            if (AllList.Count > 0)
                FileHelper.WriteList(FilePath, AllList);
        }
    }
}